package com.yaoxiaowen.project2.test.handler_multi_thread;

import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.yaoxiaowen.anno.db.DbString;
import com.yaoxiaowen.project2.R;

import java.util.TreeMap;
import java.util.concurrent.TimeUnit;

public class HandlerTestActivity extends AppCompatActivity {
    public static final String TAG = "HandlerTestActivity";
    private TextView displayTv;

    @DbString
    private Handler mHandler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_handler_test);
        displayTv = (TextView) findViewById(R.id.handlerDisplayTv);

        mHandler = new Handler();

        new MyThread("子线程").start();

    }

    class MyThread extends Thread{

        public MyThread(String name) {
            super(name);
        }

        @Override
        public void run() {
            super.run();
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    displayTv.setText("operation from " + Thread.currentThread().getName());

                }
            });
        }
    }
}
